//
//  BankAccount.swift
//  TestBankActor
//
//  Created by 罗万能 on 2025/6/17.
//
import SwiftData
import Foundation

actor BankAccount {
    var balance: Double = 0
    let id: UUID = UUID()
    
    init() {
    }
    //存款
    func deposit(amount: Double) -> Bool{
        guard amount > 0 else {
            print("Account: \(id) ,desposit \(amount) wrong!!!!")
            return false}
        balance += amount
        print("Account: \(id) ,desposit \(amount) ,balance: \(balance)")
        return true
    }
    //取款
    func withdraw(amount: Double) -> Bool{
        guard amount > 0 && balance - amount >= 0 else {
            print("Account: \(id) ,withdraw \(amount) wrong!!!!")
            return false}
        balance -= amount
        print("Account: \(id) ,withdraw \(amount),balance: \(balance)")
    return true
    }
    
    func accountInfo() {
        print( "Account: \(id) ,balance: \(balance)")
    }
    
    
}
    
    
